var urlRoot = '../qajob/';
var tagRoot = '../tagjob/';


$(function() {
	getInfo();
});

function getInfo() {
	jQuery.ajax({
		type: 'GET',
		contentType: 'application/json',
		url: urlRoot + 'info?filelist=false',
		dataType: 'json',
		async: false,
		success: function(data) {
			var model = "Unknown";
			if (checkApiCodeReturn(data, "获取模型信息出错")) {
				model = data.model;
				$("#infoHead").html("当前模型： " + model);
			}

			if (data.info)
				log(data.info);
		},
		error: function(e) {
			log("返回结果出错： " + JSON.stringify(e));
		}
	});
}

function refreshtag() {
	jQuery.ajax({
		type: 'GET',
		contentType: 'application/json',
		url: tagRoot + 'refresh',
		dataType: 'json',
		async: false,
		success: function(data) {
			if (checkApiErrorInfo(data, "Check key error")) {
				log(data.content);
			}
		},
		error: function(e) {
			log("返回结果出错： " + JSON.stringify(e));
		}
	});
}

function checktag() {
	var param = {}
	param.content = $('#textInput').val();
	param.id4 = $('#l4id').val();
	param.dolog = $('#cklog').is(":checked");

	jQuery.ajax({
		type: 'POST',
		contentType: 'application/json',
		url: tagRoot + 'parse',
		dataType: 'json',
		async: false,
		data: JSON.stringify(param),
		success: function(data) {
			if (checkApiErrorInfo(data, "Check key error")) {
				$("#simpleoutput").html(data.content);
				$("#costoutput").html("Content parse done. Cost: " + data.cost);
				log("");
			}
		},
		error: function(e) {
			log("返回结果出错： " + JSON.stringify(e));
		}
	});

}

function checkseg() {

	var param = {}
	param.content = $('#textInput').val();

	jQuery.ajax({
		type: 'POST',
		contentType: 'application/json',
		url: urlRoot + 'segcount',
		dataType: 'json',
		async: false,
		data: JSON.stringify(param),
		success: function(data) {
			if (checkApiCodeReturn(data, "Check key error")) {
				$("#simpleoutput").html(JSON.stringify(data.content));
				$("#costoutput").html("Content segment check done. Cost: " + data.cost);
				log("");
			}
		},
		error: function(e) {
			log("返回结果出错： " + JSON.stringify(e));
		}
	});
}

function chat() {

	var param = {}
	param.content = $('#textInput').val();
	param.dolog = $('#cklog').is(":checked");
	param.dosplit = $('#ckline').is(":checked");

	jQuery.ajax({
		type: 'POST',
		contentType: 'application/json',
		url: urlRoot + 'chat',
		dataType: 'json',
		async: false,
		data: JSON.stringify(param),
		success: function(data) {
			if (checkApiCodeReturn(data, "对话测试出错")) {
				console.log(data.cost);
				$("#simpleoutput").html(data.content);
				$("#costoutput").html("Talk check done. Cost: " + data.cost);
			}
		},
		error: function(e) {
			log("返回结果出错： " + JSON.stringify(e));
		}
	});

}

function checkkey() {
	var param = {}
	param.content = $('#textInput').val();
	param.num = $('#qaNum').val();
	param.type = 100;
	param.dolog = $('#cklog').is(":checked");

	jQuery.ajax({
		type: 'POST',
		contentType: 'application/json',
		url: urlRoot + 'parse',
		dataType: 'json',
		async: false,
		data: JSON.stringify(param),
		success: function(data) {
			if (checkApiCodeReturn(data, "Check key error")) {
				$("#simpleoutput").html(data.content);
				$("#costoutput").html("Content parse done. Cost: " + data.cost);
				log("");
			}
		},
		error: function(e) {
			log("返回结果出错： " + JSON.stringify(e));
		}
	});
}

function checkparse() {
	var param = {}
	param.content = $('#textInput').val();
	param.num = $('#qaNum').val();
	param.type = $('#qaType').val();

	jQuery.ajax({
		type: 'POST',
		contentType: 'application/json',
		url: urlRoot + 'parse',
		dataType: 'json',
		async: false,
		data: JSON.stringify(param),
		success: function(data) {
			if (checkApiCodeReturn(data, "问答对抽取出错")) {
				$("#simpleoutput").html(data.content);
				$("#costoutput").html("Content parse done. Cost: " + data.cost);
				log("");
			}
		},
		error: function(e) {
			log("返回结果出错： " + JSON.stringify(e));
		}
	});
}

function reset() {

	jQuery.ajax({
		type: 'GET',
		contentType: 'application/json',
		url: urlRoot + 'reset',
		dataType: 'json',
		async: false,
		success: function(data) {
			if (checkApiCodeReturn(data, "刷新出错")) {
				log(JSON.stringify(data));
			}
		},
		error: function(e) {
			log("返回结果出错： " + JSON.stringify(e));
		}
	});
}
